<?php
/**
 * Created by PhpStorm.
 * User: lyh
 * Date: 2017/3/22
 * Time: 20:05
 */

namespace Admin\Controller;


class RoleController extends CommonController{

    public function index(){
        $role=I('post.role_name');
        $Model=M('Role');
       if(!isset($role)){
            $list = $Model->order('addtime asc')->field('role_id,role_name,describe')->select();

        }else{
            $map['role_name']=array('like','%'.$role.'%');
            $list=$Model->order('addtime asc')->where($map)->field('role_id,role_name,describe')->select();
        }
        $this->assign('list',$list);// 赋值数据集
        $this->display();
    }

    public function add(){
        $arr=M('Auth')->field('auth_id,auth_pid,auth_name,auth_c,auth_a')->select();
        $result=unlimitedForLayer($arr);
        $this->assign('auth_info',$result);
        $this->display();
    }

    public function edit(){
        $role_id=$_GET['role_id'];
        $string=M('role')->where(array('role_id'=>$role_id))->field('role_auth_ids,role_name')->find();
        $role_info=explode(',',$string['role_auth_ids']);
        //1.打印角色对应的节点信息
        $role_value=array('role_id'=>$role_id,'role_name'=>$string['role_name']);
        $this->assign('role_info',$role_info);
        $this->assign('role',$role_value);
        $auth_info=M('auth')->field('auth_pid,auth_id,auth_name')->select();
        $info=unlimitedForLayer($auth_info);
        //2.打印所有的节点信息
        $this->assign('auth_info',$info);
//        echo $string['role_auth_ids'];
//        dump($role_info);
//        dump($info);
//        foreach ($info as $key=>$value)
//        {
//            echo $value['auth_id'];
//            if(in_array($value['auth_id'],$string['role_auth_ids'])){
//                echo '在';
//            }else{
//                echo '不在';
//            }
//        }
//        echo in_array($role_id,$role_info);
//        dump($role_info);
//        echo $role_id;
//        die;
        $this->display();
    }
}